using System;
using System.Collections.Generic;
using System.Text;
using Forecast.Domain;

namespace Forecast.Domain.Implementation
{
    public class Portfolio : IOwn
    {
        #region Variables

        private IDictionary<string, ICountStocks> _holdings;

        #endregion
        #region Constructors

        public Portfolio()
        {
            _holdings = new Dictionary<string, ICountStocks>();
        }

        #endregion
        #region Interface

        public ICountStocks GetHolding(IPredict prediction)
        {
            ICountStocks holding;
            if (_holdings.ContainsKey(prediction.Ticker))
            {
                holding = (ICountStocks)_holdings[prediction.Ticker];
            }
            else
            {
                holding = Holding.NULL; 
            }
            return holding;
        }

        public ICountStocks AddHolding(IPredict prediction)
        {
            ICountStocks holding;
            if (_holdings.ContainsKey(prediction.Ticker))
            {
                holding = (ICountStocks)_holdings[prediction.Ticker];
            }
            else
            {
                holding = new Holding(prediction); 
                _holdings.Add(prediction.Ticker, holding);
            }
            return holding;
        }

        public void RemoveHolding(IPredict prediction)
        {
            if (_holdings.ContainsKey(prediction.Ticker))
                _holdings.Remove(prediction.Ticker);
        }

        #endregion      
    }
}
